<template>
  <div
    id="msg"
    :style="[{ transform: 'rotate(' + deg + ')' }, { backgroundColor: color }]"
    @click="seeAdvice"
  >
    <transition appear name="fadeIn">
      <div class="Box">
        <div class="O"></div>
        <p style="font-weight: 200; font-size: 13px; color: #000; line-height: 20px">
          {{ formatTime(props.time) }}
        </p>
        <div>
          <span style="color: #fff; font-weight: 200; font-size: 14px; margin-right: 3px"
            >作者：{{ username }}</span
          >
        </div>

        <span class="adviceContent">{{ props.advice }}</span>
      </div>
    </transition>
  </div>
</template>

<script setup lang="ts">
import Bus from "@/bus";
import { defineProps, computed, defineEmits, onMounted } from "vue";
import { formatTime } from "@/formatTime";
type props = {
  username: string;
  advice: string;
  time: string;
  id: string;
  realname: string;
};
const props = defineProps({
  username: {
    type: String,
    default: "",
  },
  advice: {
    type: String,
    default: "",
  },
  time: {
    type: String,
    default: "",
  },
  id: {
    type: Number,
    default: 0,
  },
  realname: {
    type: String,
    default: "",
  },
});
onMounted(() => {
  console.log(props.advice);
});
const emit = defineEmits(["IfDel"]);
// 这里username和realname反了
const rainfallColor = [
  "rgba(255, 0, 0,.6)",
  "rgba(255, 165, 0,.6)",
  "rgba(255, 255, 0,.6)",
  "rgba(0, 255, 0,.6)",
  "rgba(0, 127, 255,.6)",
  "rgba(0, 0, 255,.6)",
  "rgba(139, 0, 255,.6)",
];
const deg = computed(() => Math.floor((0.5 - Math.random()) * 40) + "deg");
const color = computed(() => {
  let index = Math.ceil(Math.random() * 7);
  return rainfallColor[index - 1];
});

const seeAdvice = () => {
  Bus.$emit("startSeeAdvice", {
    advice: props.advice,
    color: color.value,
    username: props.username,
  });
};

</script>

<style lang="scss" scoped>
@import url("../css/comment/animate.css");
#msg {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 23px;
  display: inline-block;
  padding: 35px 15px;
  box-shadow: 0 0 6px 0px rgba(0, 0, 0, 0.7);
  transition: all 0.5s;
  box-sizing: border-box;
  vertical-align: top;
  border-radius: 20px;
  .Box {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
    overflow: hidden;
  }
  .del {
    background-color: transparent;
    border: 1px solid #00000088;
    width: 60px;
    height: 30px;
    margin-bottom: 2px;
    border-radius: 30px;
    transition: all 0.3s;
    font-weight: 200;
    // cursor: url("../assets/img/cur/mais.png"), default;

    &:hover {
      background-color: red;
      color: #fff;
    }
  }
}
#msg:hover {
  box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, 0.3);
  transform: scale(1.1) !important;
}
#msg span {
  margin-top: 25px;
  height: 40px;
  border-bottom: 1px solid black;
  letter-spacing: 1px;
  line-height: 27px;
}
.O {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 20px;
  background-color: #fff;
  top: 10px;
  left: 20px;
}
</style>
